package com.mzj.saas.mservice.bill.repository;

import com.mzj.saas.mservice.bill.entity.ExpenseBillRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface ExpenseBillRelationRepository extends PagingAndSortingRepository<ExpenseBillRelation, Long>, JpaSpecificationExecutor<ExpenseBillRelation>, JpaRepository<ExpenseBillRelation,Long> {

	ExpenseBillRelation findByHouseIdAndExpenseBillId(String houseId,Long expenseBillId);
	
	List<ExpenseBillRelation> findByExpenseBillIdIn(List<Long> expenseBillIds);
	
	@Query(value = "SELECT r.* FROM saas_expense_bill b LEFT JOIN saas_expense_bill_relation r ON b.id = r.expense_bill_id WHERE  b.payment_status = 0 AND r.contract_nubmer IN (?1)", nativeQuery = true)
	List<ExpenseBillRelation> findNoPayBill(List<String> contractNubmers);
	

}
